from tg.configuration import AppConfig, Bunch
import pydive
from pydive import model
from pydive.lib import app_globals, helpers

from routes import Mapper
from pylons import config as pylons_config
from tg.configuration import AppConfig, PylonsConfigWrapper
from pydive.config.version import app_version

config = PylonsConfigWrapper(pylons_config)
class MyAppConfig(AppConfig):
    def setup_routes(self):
        """Setup the default TG2 routes
    
        Override this and set up your own routes maps if you want to use routes.
        """
        map = Mapper(directory=config['pylons.paths']['controllers'],
                    always_scan=config['debug'])
        # Setup a default route for the root of object dispatch
        map.connect(':(controller).wsdl')
        map.connect('soap', controller='soap')
        map.connect('*url', controller='root', action='routes_placeholder')
    
        config['routes.map'] = map


base_config = MyAppConfig()
base_config.renderers = []


base_config.package = pydive

#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi') 
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
#base_config.renderers.append('chameleon_genshi') 

#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = pydive.model
base_config.DBSession = pydive.model.DBSession

# Configure the authentication backend
base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Group
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permission

# override this if you would like to provide a different who plugin for 
# managing login and logout of your application
base_config.sa_auth.form_plugin = None

# You may optionally define a page where you want users to be redirected to
# on login:
base_config.sa_auth.post_login_url = '/post_login'

# You may optionally define a page where you want users to be redirected to
# on logout:
base_config.sa_auth.post_logout_url = '/post_logout'
